home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / InspectPlot.m < prev    next >
Encoding:
Text File  |  1992-04-25  |  7.5 KB  |  274 lines

  1. /* InspectPlot.h        by Paul Kunz    June 1991
  2.  * Controls various options for displaying the plot.
  3.  *
  4.  * Copyright (C)  1991  The Board of Trustees of
  5.  * The Leland Stanford Junior University.  All Rights Reserved.
  6.  */
  7.  
  8. #import "InspectPlot.h"
  9.  
  10. const char InspectPlot_h_rcsid[] = INSPECTPLOT_H_ID;
  11. const char InspectPlot_m_rcsid[] = "$Id: InspectPlot.m,v 1.55 1992/04/24 20:51:14 pfkeb Rel $";
  12.  
  13. #import <appkit/Application.h>
  14. #import <appkit/Button.h>
  15. #import <appkit/ButtonCell.h>
  16. #import <appkit/Form.h>
  17. #import <appkit/Matrix.h>
  18. #import <appkit/NXBrowser.h>
  19. #import <appkit/NXBrowserCell.h>
  20. #import <appkit/SavePanel.h>
  21. #import <appkit/Slider.h>
  22.  
  23. #import "DrawDocument.h"
  24. #import "HDraw.h"
  25. #import "HGraphicView.h"
  26. #import "Plot.h"
  27. #import "NewInspector.h"
  28.  
  29. #import <c.h>
  30. #import <string.h>
  31. #import <float.h>
  32.  
  33. /* Tags on the Graph Type radio Buttons defined in IB 
  34.  * must be same as graphtype_t enumerated type in hippo.h 
  35.  * Here we define the rows index of grey and color bins buttons
  36.  * which both have tag of COLORPLOT
  37.  */
  38. #define GREY_ROW 2
  39. #define COLOR_ROW 3 
  40.  
  41. /* Tags on the draw options switches defined in IB */
  42. #define BOX_TAG 0
  43. #define PTS_TAG 1
  44. #define JOIN_TAG 2
  45. #define ERR_TAG 3
  46. #define TLT_TAG 4
  47. #define AXES_TAG 5
  48.  
  49.  
  50. @implementation InspectPlot
  51.  
  52. - initInspFor:aDraw
  53. {
  54.     [super initInspFor:aDraw];
  55.     [NXApp loadNibSection:"InspectPlot.nib" owner:self
  56.            withNames:NO fromZone:[self zone]];
  57.     [theInspector addView:[contentBox contentView]
  58.                  withName:"Graph Options" withSupervisor:self];
  59.     currentDim = 1;
  60.     return self;
  61. }
  62. - drawOption:sender
  63. {
  64.     drawtype_t          drawtype;
  65.     int            titlesFlag, axesFlag;
  66.  
  67.     drawtype = NONE;
  68.     if ([[drawOptMatrix findCellWithTag:BOX_TAG] state] == 1) 
  69.         drawtype |= BOX;
  70.     if ([[drawOptMatrix findCellWithTag:PTS_TAG] state] == 1)
  71.         drawtype |= POINT;
  72.     if ([[drawOptMatrix findCellWithTag:JOIN_TAG] state] == 1)
  73.     drawtype |= LINE;
  74.     if ([[drawOptMatrix findCellWithTag:ERR_TAG] state] == 1)
  75.     drawtype |= ERRBAR;
  76.  
  77.     [graphicView graphicsPerform:@selector(setDrawType:)
  78.                            with :(id)&drawtype andDraw:NO];
  79.     
  80.     titlesFlag = [[drawOptMatrix findCellWithTag:TLT_TAG] state ];
  81.     [graphicView graphicsPerform:@selector(setTitlesFlag:)
  82.                            with :(id)&titlesFlag andDraw:NO];
  83.     
  84.     axesFlag = [[drawOptMatrix findCellWithTag:AXES_TAG] state ];
  85.     [graphicView graphicsPerform:@selector(setAxesFlag:)
  86.                            with :(id)&axesFlag andDraw:YES];
  87.     
  88.     [[graphicView window] flushWindow];
  89.     return self;
  90. }
  91.  
  92. - graphOption:sender
  93. {
  94.         int        color;
  95.     drawtype_t    dt;
  96.     
  97.     graphtype = [[graphTypMatrix selectedCell] tag]; 
  98.     color = 0;
  99.     if (                   ( graphtype == COLORPLOT) &&
  100.          ([graphTypMatrix selectedRow] == COLOR_ROW)    ) {
  101.         color = 1;
  102.     }
  103.     
  104.     if (graphtype == XYPLOT || graphtype == STRIPCHART)
  105.     {
  106.          [selectedPlot getDrawType: &dt];
  107.          if (! (dt & (LINE+POINT+ERRBAR)) )
  108.          {
  109.           dt += POINT;
  110.           [graphicView graphicsPerform:@selector(setDrawType:)
  111.                 with :(id)&dt andDraw:NO];
  112.          }
  113.     }
  114.     
  115.     [graphicView graphicsPerform:@selector(setDispType:)
  116.         with :(id)&graphtype andDraw:NO];
  117.     [graphicView graphicsPerform:@selector(setColorType:)
  118.         with :(id)&color andDraw:YES];
  119.         [[graphicView window] flushWindow];
  120.  
  121.         [self updateView];
  122.  
  123.         return self;
  124. }
  125.  
  126. - titleForm:sender
  127. {
  128.     const char        *string;
  129.     
  130.     string = [titleForm stringValueAt:0];
  131.     [graphicView graphicsPerform:@selector(setTitle:)
  132.                         with:(id)string andDraw:NO];
  133.     string = [titleForm stringValueAt:1];
  134.     [graphicView graphicsPerform:@selector(NameAxisX:)
  135.                         with:(id)string andDraw:NO];
  136.     string = [titleForm stringValueAt:2];
  137.     [graphicView graphicsPerform:@selector(NameAxisY:)
  138.                         with:(id)string andDraw:YES];
  139.     [[graphicView window] flushWindow];
  140.     return self;
  141. }
  142. - resetTitle:sender
  143. {
  144.     const char    *string;
  145.     char    disp_string[80];
  146.     ntuple    nt;
  147.     display    disp;
  148.     int        index;
  149.     
  150.     if ( !selectedPlot ) {
  151.         return self;
  152.     }
  153.     nt = [selectedPlot ntuple];
  154.     if ( !nt ) {
  155.         return self;
  156.     }
  157.     index = [sender selectedCol];
  158.     switch (index) {
  159.         case 0 :
  160.         string = h_getNtTitle(nt);
  161.         [titleForm setStringValue:string at:0];
  162.         [graphicView graphicsPerform:@selector(setTitle:)
  163.                     with:(id)string andDraw:YES];
  164.         break;
  165.     case 1 :
  166.         disp = [selectedPlot histDisplay];
  167.         index = h_getBinding(disp, XAXIS);
  168.         string = h_getNtLabel( nt, index );
  169.         [titleForm setStringValue:string at:1];
  170.         [graphicView graphicsPerform:@selector(NameAxisX:)
  171.                     with:(id)string andDraw:YES];
  172.         break;
  173.     case 2 :
  174.         disp = [selectedPlot histDisplay];
  175.         if ( h_getDispType(disp) == HISTOGRAM ) {
  176.             string = "Entries / %dx bin";
  177.         } else {
  178.         index = h_getBinding( disp, YAXIS );
  179.         string = h_getNtLabel( nt, index );
  180.         }
  181.         [graphicView graphicsPerform:@selector(NameAxisY:)
  182.                     with:(id)string andDraw:YES];
  183.         h_expandLabel( disp_string, string, 80, disp );
  184.         [titleForm setStringValue:disp_string at:2];
  185.         break;
  186.     }
  187.     [[graphicView window] flushWindow];
  188.     return self;
  189. }
  190. /* Methods to support updating the inspector's View */
  191. - updateView
  192. {
  193.     int                 pos;
  194.     drawtype_t          drawtype;
  195.     char string[80];
  196.  
  197.     if ( !selectedPlot ) {
  198.         return self;
  199.     }
  200.     [selectedPlot getDispType:&graphtype];
  201.     if (graphtype == HISTOGRAM)
  202.      currentDim = 1;
  203.     else 
  204.      currentDim = 2;
  205.     
  206.  
  207.     pos = graphtype;
  208.     if ( graphtype != COLORPLOT ) {
  209.         [graphTypMatrix selectCellWithTag:pos];
  210.     } else {
  211.     [selectedPlot getDrawType:(drawtype_t *) &drawtype];
  212.         if ( drawtype & COLOR ) {
  213.         [graphTypMatrix selectCellAt:COLOR_ROW :0 ];
  214.     } else {
  215.         [graphTypMatrix selectCellAt:GREY_ROW :0];
  216.     }
  217.     }
  218.     if ( [selectedPlot isCutPlot] ) {
  219.         [graphTypMatrix setEnabled:NO];
  220.     } else {
  221.         [graphTypMatrix setEnabled:YES];
  222.     }
  223.     [graphTypMatrix display];
  224.     
  225.     if (graphtype == HISTOGRAM || graphtype == XYPLOT ||
  226.     graphtype == STRIPCHART) 
  227.     {
  228.     [selectedPlot getDrawType:(drawtype_t *) & drawtype];
  229.     pos = drawtype & BOX;
  230.     if (pos > 0)
  231.         pos = 1;
  232.     [[drawOptMatrix findCellWithTag:BOX_TAG] setState:pos];
  233.     [[drawOptMatrix findCellWithTag:BOX_TAG] setEnabled:YES];
  234.     
  235.     pos = drawtype & POINT;
  236.     if (pos > 0)
  237.         pos = 1;
  238.     [[drawOptMatrix findCellWithTag:PTS_TAG] setState:pos];
  239.     [[drawOptMatrix findCellWithTag:PTS_TAG] setEnabled:YES];
  240.     
  241.     pos = drawtype & LINE;
  242.     if (pos > 0)
  243.         pos = 1;
  244.     [[drawOptMatrix findCellWithTag:JOIN_TAG] setState:pos];
  245.     [[drawOptMatrix findCellWithTag:JOIN_TAG] setEnabled:YES];
  246.     
  247.     pos = drawtype & ERRBAR;
  248.     if (pos > 0)
  249.         pos = 1;
  250.     [[drawOptMatrix findCellWithTag:ERR_TAG] setState:pos];
  251.     [[drawOptMatrix findCellWithTag:ERR_TAG] setEnabled:YES];
  252.     } else {
  253.     [[drawOptMatrix findCellWithTag:BOX_TAG] setEnabled:NO];
  254.     [[drawOptMatrix findCellWithTag:PTS_TAG] setEnabled:NO];
  255.     [[drawOptMatrix findCellWithTag:JOIN_TAG] setEnabled:NO];
  256.     [[drawOptMatrix findCellWithTag:ERR_TAG] setEnabled:NO];
  257.     }
  258.     [[drawOptMatrix findCellWithTag:TLT_TAG] 
  259.          setState:[selectedPlot titlesFlag]];
  260.     [[drawOptMatrix findCellWithTag:AXES_TAG] 
  261.          setState:[selectedPlot axesFlag]];
  262.      
  263.     [drawOptMatrix display];
  264.     
  265.     [titleForm setStringValue:[selectedPlot title]      at:0];
  266.     [titleForm setStringValue:[selectedPlot axisLabelX] at:1];
  267.     h_expandLabel( string, [selectedPlot axisLabelY], 80,
  268.                            [selectedPlot histDisplay] );
  269.     [titleForm setStringValue:string at:2];
  270.     
  271.     return self;
  272. }
  273. @end
  274.